<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

defined('_JEXEC') or die('Retricted Access');
$url = $mainframe->isAdmin() ? $mainframe->getSiteURL() : JURI::base();

JHTML::_('behavior.tooltip');
?>
<?php JHTML::_('behavior.modal', 'a.modal'); ?>
<?php 
	global $jbconfig;
	global  $option;
	$user = JFactory::getUser();
	
	$salary_min = getEditFieldList('ja_jobs'," and field_name='salary_min'");
	$salary_max = getEditFieldList('ja_jobs'," and field_name='salary_max'");
	
?>
<script type="text/javascript" language="javascript">
/* <![CDATA[ */
user_name = '';
user_id = '';

function NumberOnly1(ele) {
		if (!/^\d*$/.test(ele.value)) {
			ele.value = ele.value.replace(/[^\d]/g,"")
		}
	}

function validate()
{
	form = document.jobalertForm;
	
	if(form.keyword.value.trim()!='' && form.keyword.value.trim().length<3){
		alert('<?php echo JText::_("Minimum length of keyword must be at least 3 characters"); ?>');
		form.keyword.focus();
		return false;
	}
	
	if( $('zipcode_from') ){
		if(form.zipcode_from.value != ""){
			if( !checkNumber(form.zipcode_from.value) ){
				alert('<?php echo JText::_("The Zipcode value must be the numeric string"); ?>');
				form.zipcode_from.focus();
				return false;
			}
			
			if( !checkNumber(form.zipcode_distance.value) ){
				alert('<?php echo JText::_("The Distance value must be the numeric string"); ?>');
				form.zipcode_distance.focus();
				return false;
			}
		}
	}
	
	return true;
}

// Check numberic value
function checkNumber(value){    
	var numericExpression = /^[0-9]+$/;
	var numericExpression1 = /^[0-9]+\.[0-9]{1,2}$/;
	
	if ( value.match(numericExpression) || value.match(numericExpression1) )
	   return true
	else return false;
}

function cancel_select_employer()
{
	document.getElementById('sbox-window').close();
}

function remove_emp(user_id,obj_id)
{
	obj = document.getElementById(obj_id);
	obj.innerHTML = '';
	select_user_id = document.getElementById('job_author').value;
	select_user_id = select_user_id.replace(','+user_id,'');
	select_user_id = select_user_id.replace(user_id,'');
	
	document.getElementById('job_author').value = select_user_id;
}

function checkbox_clicked(obj,checkbox_type,index)
{	
	if (checkbox_type=='category'){			
		for (i=index;i<child_category[obj.alt].length;i++)
		{
			ele = document.getElementById(checkbox_type+'_'+child_category[obj.alt][i]);
			ele.checked = obj.checked;
			if (child_category[ele.alt].length>0)
			{
				temp = i;
				checkbox_clicked(ele,checkbox_type,0);
				i = temp;
			}
		}
	}else
		for (i=index;i<child_location[obj.alt].length;i++)
		{
			ele = document.getElementById(checkbox_type+'_'+child_location[obj.alt][i]);
			ele.checked = obj.checked;
			if (child_location[ele.alt].length>0) 
			{
				temp = i;
				checkbox_clicked(ele,checkbox_type,0);
				i = temp;
			}
		}
		return index;
}
/* ]]> */
</script>

<style>
.job_search_category {
	max-height: 200px;
	overflow: scroll !important; 
	width:270px;
}
</style>

<!--[if gt IE 7.0]>
<style type="text/css">
/* <![CDATA[ */
.job_search_category {
	height: 200px;
	overflow: scroll !important; 
	width:270px;
}
/* ]]> */
</style>
<![endif]-->


<div id="jobboard-content">
 	<form name="jobalertForm" action="" method="post" enctype="multipart/form-data">
 	<div class="moduletable job-alert">
 		<h3><?php echo JText::_('Filter information') ?></h3>
		<table class="tabledata">
		
			
			<tr class="sectiontableentry2">
				<td>
					<label for="keyword"><?php echo JText::_("Find keywords"); ?></label>
				</td>
				<td>
					<input size="50" type="text" name="keyword" value="" id="keyword" />
					<span class="editlinktip hasTip" title="<b><?php echo JText::_( 'Keyword' ) ?></b>:<br /><?php echo JText::_('Please insert a specific tittle (eg. Chief Accountant, Marketing manager) into keyword box to refine your results')?>"><img border="0" alt="Tooltip" src="<?php echo $url; ?>/includes/js/ThemeOffice/tooltip.png"/></span>
				</td>
			</tr>
			<tr class="sectiontableentry1">
				<td>
					<label><?php echo JText::_("Job must match"); ?></label>
				</td>
				<td>
					<input type="radio"  name="keyword_option" value="1" /><label><?php echo JText::_("Any keyword"); ?></label><br />
					<input type="radio"  name="keyword_option" value="2" /><label><?php echo JText::_("All the keywords"); ?></label>
					<span class="editlinktip hasTip" title="<b><?php echo JText::_( 'Keyword option' ) ?></b>:<br /><?php echo JText::_('JOB SEARCH FORM - KEY WORD TIP')?>"><img border="0" alt="Tooltip" src="<?php echo $url; ?>/includes/js/ThemeOffice/tooltip.png"/></span><br />
					<input type="radio"  name="keyword_option" value="3" /><label><?php echo JText::_("The exact phrase"); ?></label>
				</td>
			</tr>
			<tr class="sectiontableentry2">
				<td>
					<label><?php echo JText::_("Categories"); ?></label>
				</td>
				<td>
					<?php echo $this->objCategory; ?>
				</td>
			</tr>
			<tr class="sectiontableentry1">
				<td>
					<label><?php echo JText::_("Locations"); ?></label>
				</td>
				<td>
					<?php echo $this->objLocation; ?>
				</td>
			</tr>
			<!--<tr class="sectiontableentry2">
				<td>
					<label><?php echo JText::_("Radius (km)"); ?></label>
				</td>
				<td>
					<?php echo $this->objJobDistance; ?>
				</td>
			</tr>-->
			
		<?php if (count($salary_min)>0) 
				if (($salary_min[0]->field_state=='add'||$salary_min[0]->field_state=='chg')&&($salary_min[0]->display=='show_all'||$salary_min[0]->display=='hide_on_view'||$salary_min[0]->display=='hide_on_edit'))
				{?>
			<tr class="sectiontableentry1">
				<td>
					<label for="filter_salary_from"><?php echo JText::_('Salary Minimum'); ?></label>
				</td>
				<td>	
					
					<input onkeyup="NumberOnly1(this)" type="text" name="filter_salary_from" style="width:150px;" value="" id="filter_salary_from" />
				</td>
			</tr>
		<?php } ?>
		<?php if (count($salary_max)>0) 
				if (($salary_max[0]->field_state=='add'||$salary_max[0]->field_state=='chg')&&($salary_max[0]->display=='show_all'||$salary_max[0]->display=='hide_on_view'||$salary_max[0]->display=='hide_on_edit'))
				{?>
			<tr  class="sectiontableentry2">
				<td><label for="filter_salary_to"><?php echo JText::_('Salary Maximum'); ?></label></td>
				<td>	
					<input onkeyup="NumberOnly1(this)" type="text" name="filter_salary_to" style="width:150px;" value="" id="filter_salary_to" />
				</td>
			</tr>
		<?php } ?>
			<tr class="sectiontableentry1">
				<td><label for="job_type"><?php echo JText::_('Job type'); ?></label></td>
				<td>
					<?php echo $this->objJobType; ?>
					
				</td>
				
			</tr>
			<tr class="sectiontableentry2">
				<td><label for="posted_date"><?php echo JText::_("Job Posted In The Last"); ?></label></td>	
				<td>
					
					<?php echo $this->objPostedDate; ?>
				</td>
			</tr>
			<tr  class="sectiontableentry1">
				<td><?php echo JText::_('Job posted by'); ?></td>
				<td>
					<span id="s_selected_employer"></span>
					<a class="modal" rel="{handler: 'iframe', size: {x: 850, y: 475}}" href="index.php?option=com_jajobboard&view=jajobalerts&layout=element_user&tmpl=component&limitstart=<?php echo JRequest::getVar('limitstart',0); ?>" title="Select an User">(<?php echo JText::_('Select employer'); ?>)</a>
					<input type="hidden" size="70" name="job_author" id="job_author" value="" />
				</td>
			</tr>
			
			<?php
			
			// Zip code distance search area
			
			// Check enable in Form Field
			$enable = false;
			$model 	= &$this->getModel();
			$result = $model->getFilterField();
			
			if($result){
				if( checkField_inserted($result->referred_table, $result->referred_key) ){
		             $enable = true;
		         } else {		             
		             JError::raiseNotice(0, "Zip/Postal code reference table/key does not exist");
		         }
			}
			
			/*$enable = $jbconfig['general']->get("enable_zipcode", 0);
			if( $enable ){
			    $field = $jbconfig['general']->get("zip_field_name", "");
			    if( checkField_inserted("ja_jobs", $field) ){
			         // Check reference table exist
			         $table = $jbconfig['general']->get("zip_reference_table", '');
			         if( checkField_inserted($table, 'zipcode') ){
			             $enable = true;
			         }else{
			             $enable = false;
			             JError::raiseNotice(0, "Zip/ Postal code reference table name is not exist");
			         }
			    }else{
			        $enable = false;
			        JError::raiseNotice(0, "Zip/ Postal field name in Job Form is not exist");
			    }
			}*/
			if( $enable ){
			?>
			<tr  class="sectiontableentry1">
				<td><?php echo JText::_('Distance'); ?></td>
				<td>
					<?php echo JText::_("From Zipcode");?>: <input type="text" id="zipcode_from" name="zipcode_from" size="10"/> <?php echo JText::_("Radius");?>: <input id="zipcode_distance" type="text" name="zipcode_distance" size="10"/> (<i>miles</i>)
				</td>
			</tr>
			<?php } ?>
						
		</table>
	    <table class="tabledata"> 
	        <tr>
	            <td>
	            	<div align="center" style="width:100%;">
		                <input class="button" type="submit" onclick="return validate()"  value="<?php echo JText::_('Search'); ?>" />
            		</div>
	            </td>
	        </tr>
	    </table>		   
	    <input type="hidden" name="option" value="<?php echo JBCOMNAME; ?>" />
		<input type="hidden" name="view" value="jajobs" />
		<input type="hidden" name="layout" value="searchform_result" />
		<input type="hidden" name="Itemid" value="<?php echo $this->Itemid; ?>" />	
		<?php echo JHTML::_( 'form.token' ); ?>	
	</div>			
 	</form> 
</div>
